﻿using AutoMapper;
using B.S.Packaged.Domain;
using B.S.Packaged.ErrorCode;
using B.S.Packaged.WebAPI.Read.Application.Command.ReportCommand;
using MediatR;
using SqlSugar;

namespace B.S.Packaged.WebAPI.Read.Application.CommandHander.ReportCommandHander
{
    public class ShowReportCommandHander : IRequestHandler<ShowReportCommand, APIResult<List<Report>>>
    {
        private readonly IMapper mapper;
        private readonly ISqlSugarClient db;

        public ShowReportCommandHander(IMapper mapper, ISqlSugarClient db)
        {
            this.mapper = mapper;
            this.db = db;
        }

        public async Task<APIResult<List<Report>>> Handle(ShowReportCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Report>> result = new APIResult<List<Report>>();

            var list = await db.Queryable<Report>()
                                .Where(x => x.Del == false && x.ReportId == request.ReportId)
                                .ToListAsync();

            result.data = list;

            result.code = APIResultCode.success;
            result.msg = "查询成功";

            return await Task.FromResult(result);
        }
    }
}
